package com.ctbri.vSearch.dao.neo4j;

import java.sql.Connection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;

import javax.annotation.Resource;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;

import com.ctbri.vSearch.frame.Neo4jPooledConnection;
import redis.clients.jedis.Jedis;

@Component
public class RelationMapQurey {
	@Autowired
    private TaskExecutor taskExecutor;
	@Resource
	Neo4jPooledConnection neo4jPooledConnection;
	
	public void queryRelationMap(Neo4jQueryDao neo4jQuery,	CountDownLatch countdownlatch,
			String word, List<String> nodes,List<String> links,	ObjectMapper mapper, 
			String[] category, Jedis client){
		taskExecutor.execute(new Neo4jQueryThread(neo4jQuery, countdownlatch,word, nodes, 
				links,mapper, category, client));
	}
	
	public Map<String, Double> queryRelationWords(String word ){
		Map<String, Double> res = new HashMap<>();
		Connection conn =null;
		try {
			conn =neo4jPooledConnection.getCurrentConnecton();
			res = Neo4JAccess.queryRelatedWords(conn,word);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("查询错误");
		}finally{
			neo4jPooledConnection.releaseConnection(conn);
		}
		Set<String> resSet = res.keySet();
		for(String r :resSet ){
			System.out.println(r);
		}
		res.put(word, 10.0);
		return res;
	}
	
}
